home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / host / Host_ByInetAddr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  1.8 KB  |  66 lines

  1. /* 
  2.  * Host_ByInetAddr.c --
  3.  *
  4.  *    Source code for the Host_ByInetAddr library procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /user6/voelker/src/hosttest/RCS/Host_ByInetAddr.c,v 1.1 92/03/26 19:45:48 voelker Exp Locker: voelker $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <stdio.h>
  21. #include <host.h>
  22. #include <hostInt.h>
  23.  
  24.  
  25. /*
  26.  *-----------------------------------------------------------------------
  27.  *
  28.  * Host_ByInetAddr --
  29.  *
  30.  *    Find information about the host with the given internet address.
  31.  *
  32.  * Results:
  33.  *    A Host_Entry structure, or NULL if no host exists in the database
  34.  *    with the given internet address.  The Host_Entry is statically
  35.  *    allocated, and may be modified on the next call to any Host_
  36.  *    procedure.
  37.  *
  38.  * Side Effects:
  39.  *    The host database file is opened if it wasn't already.
  40.  *
  41.  *-----------------------------------------------------------------------
  42.  */
  43.  
  44. Host_Entry *
  45. Host_ByInetAddr(inetAddr)
  46.     register Net_InetAddress inetAddr;  /* Address to match. */
  47. {
  48.     register Host_Entry         *entry;
  49.     register int             i;
  50.  
  51.     if (Host_Start() == 0 && Net_InetAddrCmp(inetAddr, 0)) {
  52.     while (1) {
  53.         entry = Host_Next();
  54.         if (entry == (Host_Entry *) NULL) {
  55.         return (Host_Entry *) NULL;
  56.         }
  57.         for (i = 0; i < HOST_MAX_INTERFACES; i++) {
  58.         if (!Net_InetAddrCmp(entry->nets[i].inetAddr, inetAddr)) {
  59.             return (entry);
  60.         }
  61.         }
  62.     }
  63.     }
  64.     return ((Host_Entry *)NULL);
  65. }
  66.